<?php

class Contact_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    /**
     *
     * @param type $type
     * @param type $value
     * @return result of type & value (example: type = 'id', value = '1')
     */
    public function get_message($type = FALSE, $value = FALSE) {
        if ($type === FALSE OR $value === FALSE) {
            $query = $this->db->get('message');
            return $query->result_array();
        } else {
            $query = $this->db->get_where('message', array($type => $value));
            return $query->row_array();
        }
    }

//    public function set_message() {
//        $data = array(
//            'email' => $this->input->post('txt_email'),
//            'name' => $this->input->post('txt_name'),
//            'subject' => $this->input->post('txt_subject'),
//            'message' => $this->input->post('txt_message'),
//        );
//        $this->load->library('email');
//
//        //Send email to client
//        $this->email->from('techstormteamwork@gmail.com', 'TechStorm');
//        $this->email->to($data['email']);
//        $this->email->subject('TechStorm - Fly you to success!');
//        //Send notification email to admin
//
//        return $this->db->insert('message', $data);
//    }

    public function set_message($data) {
//        $data = array(
//            'email' => $this->input->post('txt_email'),
//            'name' => $this->input->post('txt_name'),
//            'subject' => $this->input->post('txt_subject'),
//            'message' => $this->input->post('txt_message'),
//        );
        $this->load->library('email');

        //Send email to client
        $this->email->from('techstormteamwork@gmail.com', 'TechStorm');
        $this->email->to($data['email']);
        $this->email->subject('TechStorm - Fly you to success!');
        $this->email->message('You have sent an message to TechStorm website. We will reply to you soon :-)');
        $this->email->send();
        //Send notification email to admin

        return $this->db->insert('message', $data);
    }

}
